const Service = require('egg').Service;
const crypto = require('crypto');

class Md5Service extends Service {

    /**
     * 不带盐的加密方式
     * @param {*} password 
     */
    async cryptoPassFunc(password) {
        const md5 = crypto.createHash('md5');
        return md5.update(password).digest('hex');
    }

    /**
     * 带盐的加密方式
     * @param {*} password 
     */
    async saltPasswordFunc(password, salt) {
        // 密码加盐
        const saltPassword = password + ':' + salt;
        const md5 = crypto.createHash('md5');
        const result = md5.update(saltPassword).digest('hex');
        return result;
    };

}

module.exports = Md5Service;